package com.ares.aler.until;

import com.ares.aler.service.UserDao;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/*
* 继承这个类之后会进行自启动
* 启动，自己启动 必须得有 @controller 注释才能生效
 */
@Controller
public class InitBeanTask implements InitializingBean {

    @Autowired
    UserDao userDao;

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("saaaa");
        ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor();
        // 参数：1、任务体 2、首次执行的延时时间
        //      3、任务执行间隔 4、间隔时间单位
        service.scheduleAtFixedRate(()->userDao.birthdaySelectMsg(), 0, 43200, TimeUnit.SECONDS);

    }

}
